#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <climits>
#include <cstdio>
#include <unordered_map>

/*
https://www.nowcoder.com/test/question/f5a3b5ab02ed4202a8b54dfb76ad035e?pid=30440590&tid=45779887
*/

using namespace std;

const static auto sync_off=[](){
    ios::sync_with_stdio(0);
    cin.tie(0);
    return nullptr;
}();

int check(int i,int j,vector<vector<int>> &v){
    int val=v[i][0]+v[j][0];
    for(int k=1;k<v[0].size();k++){
        if(v[i][k]+v[j][k]!=val){
            return false;
        }
    }
    return true;
}

int main(){
    freopen("in.txt","r",stdin);
    int n,k;
    vector<vector<int>> v;
    vector<int> mp[2005]; 

    cin >> n>>k;
    int cnt=0;
    for(int i=0;i<n;i++){
        vector<int> vv(k,0);
        for(int j=0;j<k;j++){
            cin >> vv[j];
        }
        v.push_back(vv);
        int d=v[i][k-1]-v[i][0];
        
        for(int i1=0;i1<mp[1000-d].size();i1++){
            if(check(i,mp[1000-d][i1],v)){
                cnt++;
            }
        }
        
        mp[1000+d].push_back(i);
    }
    cout << cnt <<endl;
    


    return 0;
}